<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/mobile/include/taglib.jsp"%>
<html>
<head>
	<title>商品详情</title>
	<%@include file="/WEB-INF/views/mobile/include/head.jsp" %>
	<script type="text/javascript"> 
	var appId = '${appId}';
	var sid="${merchant.id}";
	var mobile="${mobile}";
	var classifyId = "${classifyId}";
	var shopModel = "${shopModel}";
	var product = new Object();
	var products = new Array();
	var totalNumber = ${totalNumber};
	var totalAmount = ${totalAmount};
	var ctxFront = "${ctxFront}";
	var ctxShop = "${ctxShop}";
	var userType = "${userType}";//用户类型，0新用户
	$(document).ready(function() {
		initRichTextSize($(".pro-detail-desc"), $("#inputForm").width()-20);
		var item = new Object();
		item.id="${product.id}";
		item.price=${product.price};
		item.startSaleNum=${product.startSaleNum}; //起购量
		item.purchaseNum=${product.purchaseNum};   //限购量
		item.cartId="${product.cartId}";	 //购物车里对应该商品编号
		item.number=${product.number};   //购物车里对应该商品购买数量
		item.amount=${product.amount};   //购物车里对应该商品购买金额
		product = item;
		products.push(item);
		//调用判断商品是否可以操作
		checkShoppingCartAddOrDiffIcon(item);
	});
	//增加商品
	function addProduct(productId, gift){
		if(gift=="1" && userType=="1"){//商品是新用户礼包并且用户是老用户，则不允许添加
			openPopup("仅限新用户领取！");
			closePopup(3000);
			return;
		}
		addProductCart(productId);
	}
	</script>
	<script type="text/javascript"> 
		$(document).ready(function() {
			//预加载图片
			startLoadImage();
		});
		function startLoadImage(){
			$(".displayImages").each(function(index){
				loadImage($(this).attr("id"),$(this).attr("path"),loadResult);
			});
		}
	</script>
	<script type="text/javascript"> 
	function iEventGetNavgitionInfo(){
		var result = {
			title:"商品详情",
		    leftBtn:{ 
		    	type:2,	//0,只显示返回,1只显示关闭，2显示返回，关闭
				backFun:""   //返回执行的事件，不带的话由iOS控制。
			}               
		};
		if($global_isAndroid){
			window.control.onJsComplete(JSON.stringify(result));
			return;
		}
		return JSON.stringify(result);
	}
	
	//跳转到购物车
	function showShoppingCart(){
		//验证是否登录
		if(!checkLogin()) return;
		
		loading('正在跳转，请稍等...');
		setTimeout(function(){
			hideLoader();
			document.location="${ctxShop}/shoppingcart?sid="+sid+"&mobile="+mobile+"&classifyId="+classifyId+"&shopModel="+shopModel+"&appId="+appId+"&detail=${product.id}";				
		},1000);
	}
	</script>
</head>
<body data-role="page" style="background-color: #F0F0F0;">
	<div role="main" class="ui-content" style="padding: 0px 0px 45px;">
		<div id="popup" data-role="popup" data-position-to="window" data-overlay-theme="a" data-theme="b" class="ui-content">
		  <p></p>
		</div>
		<%@include file="/WEB-INF/views/mobile/layouts/checkLoginPopup.jsp" %>
		<form:form id="inputForm">
			<input id="totalAmount" name="totalAmount" type="hidden" value="${totalAmount }" />
			<div class="pro-detail-top">
				<div class="pro-detail">
					<img id="photo0" class="displayImages" src="${ctxFront }/images/loading.png" style="width:149px; height:84px;" path="${ctxShop}/download?filePath=${product.logoUrl }" />
				</div>
				<div class="pro-detail">
					${product.name }<br/>${product.assisTitle }
				</div>
				<div class="pro-detail"><strong class="amount">￥${product.price }</strong>/ ${product.productUnit.name }</div>
			</div>
			<div class="pro-detail-middle">
				<div class="pro-detail-title">
					购买须知
				</div>
			</div>
			<div class="pro-detail-middle">
				<div class="pro-detail-desc">
					${product.shouldKnow }
				</div>
			</div>
			<div class="pro-detail-middle" style="margin-top: -10px;margin-bottom: 10px;">
				<div class="pro-detail-title" style="padding-top: 5px;">
					商品简介
				</div>
			</div>
			<div class="pro-detail-middle">
				<div class="pro-detail-desc">
					${product.remarks }
				</div>
			</div>
		</form:form>
	</div>
	<div data-role="footer" class="ui-footer" data-position="fixed" data-tap-toggle="false">
		<div class="float-left footer-left" style="width: 50%;">
			<div class="a" style="display: none;"><label class="float-left">总金额：</label><label class="float-left amount totalAmount"><strong>￥${totalAmount }</strong></label></div>
			<p id="${product.id }" style="padding: 0px; margin: 10px 1em 10px 0px;">
	        	<img class="float-right add" style="width: 30px; height: 30px;" status="1" onclick="addProduct('${product.id}',${product.gift })" alt="" src="${ctxFront }/images/shop/add-2.png"/>
	        	<label class="float-right choice-num" style="height: 30px;"><strong>${product.number }</strong></label>
	        	<img class="float-right diff" style="width: 30px; height: 30px;" status="0" onclick="diffProductCart('${product.id}', 0)" alt="" src="${ctxFront }/images/shop/diff-1.png">
	        </p>
	    </div>
	    <!-- 
		<div class="float-right footer-right" style="width: 50%;">
			<img class="float-right" alt="" src="${ctxFront }/images/shop/gwc_0.png" height="35" style="margin: 7.5px 1em 7.5px 0px;" onclick="joinShoppingCart()">
	    </div>
	     -->
		<div class="float-right footer-right" style="width: 50%;">
			<div class="b"><img class="float-right" alt="" src="${ctxFront }/images/shop/gwc_0.png" onclick="showShoppingCart()"></div>
			<div class="badger-css totalNumber-badger" style="${totalNumber==0?'display:none;':'' }" onclick="showShoppingCart()"><div class="badger-badge totalNumber" style="border-radius:50%">${totalNumber }</div></div>
	    </div>
	</div><!-- /footer -->
</body>
</html>